package com.example.selfcontrol.entity.resp;

import com.example.selfcontrol.entity.Comment;
import com.example.selfcontrol.entity.User;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class CommentResponse {
    // 用于存放子评论的列表
    private Long id ;
    private String content ;
    private Date createtime ;

    private Long attachArticle ;

    // 根据id找到对应的User补全下面字段
    private String author ;
    private String authorPicture ;

    // 通过外键装配一个评论类
    public static CommentResponse CreateCommentResponse(User user ,Comment comment) {
        CommentResponse res = new CommentResponse() ;

        res.setId(comment.getId());
        res.setContent(comment.getContent());
        res.setCreatetime(comment.getCreatetime());
        res.setAttachArticle(comment.getAttachArticle());
        // 这个user.getName() --- 容易异常
        res.setAuthor(user.getName());

        res.setAuthorPicture(user.getPicture());

        return res ;
    }


}
